import { gitlabOApiFetch } from '../fetch';

const gitlabApi = gitlabOApiFetch();
/**
 * 获取gitlab项目列表
 * @param params 请求参数
 * @returns 结果
 */
export const getProjects = (params: { private_token: string; per_page: number; page: number }): Promise<any[]> => {
  return gitlabApi.get('/projects', { params });
};
/**
 * 获取gitlab项目分支
 * @param params 请求参数
 * @returns 结果
 */
export const getProjectDetailById = (params: { private_token: string; id: number | string }): Promise<any[]> => {
  return gitlabApi.get(`/projects/${params.id}`, { params });
};
/**
 * 获取gitlab项目分组列表
 * @param params 请求参数
 * @returns 结果
 */
export const getGroups = (params: { private_token: string; per_page: number; page: number }): Promise<any[]> => {
  return gitlabApi.get('/groups', { params });
};
/**
 * 获取gitlab项目分支
 * @param params 请求参数
 * @returns 结果
 */
export const getBranchesList = (params: { private_token: string; id: number | string; per_page: number; page: number }): Promise<any[]> => {
  return gitlabApi.get(`/projects/${params.id}/repository/branches`, { params });
};
/**
 * 获取gitlab某一个分支的提交记录
 */
export const getBranchCommitList = (params: { private_token: string; id: number | string; ref_name: string; per_page: number; page: number }): Promise<any[]> => {
  return gitlabApi.get(`/projects/${params.id}/repository/commits`, { params });
};
/**
 * 获取gitlab某个分支最后一次提交
 */
export const getBranchCommitLastest = (params: { private_token: string; id: number | string; sha: string }): Promise<any[]> => {
  return gitlabApi.get(`/projects/${params.id}/repository/commits/${params.sha}`, { params });
};
/**
 * 在存储库中创建一个新分支.
 */
export const postNewBranch = (params: { private_token: string; id: number | string; branch: string; ref: string }): Promise<any[]> => {
  return gitlabApi.post(`/projects/${params.id}/repository/branches`, params);
};
/**
 * 获取单个项目存储库分支
 */
export const getSingleBranch = (params: { private_token: string; id: number | string; branch: string }): Promise<any[]> => {
  return gitlabApi.get(`/projects/${params.id}/repository/branches/${params.branch}`, { params });
};
/**
 * 创建mr
 */
export const postNewMR = (params: { id: number | string; private_token: string; source_branch: string; target_branch: string; title: string }): Promise<any[]> => {
  return gitlabApi.post(`/projects/${params.id}/merge_requests`, params);
};
/**
 * 更新mr
 */
export const postUpdateMR = (params: { id: number | string; private_token: string; source_branch: string; target_branch: string; iid: number }): Promise<any[]> => {
  return gitlabApi.post(`/projects/${params.id}/merge_requests/${params.iid}`, params);
};
/**
 * 获取提交记录在哪些分支存在
 */
export const getRefs = (params: { id: number | string; sha: string; private_token: string }): Promise<any[]> => {
  return gitlabApi.get(`/projects/${params.id}/repository/commits/${params.sha}/refs?type=branch`, { params });
};
